package com.icss.ah.activity.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.icss.ah.activity.service.PromotionStatisticsService;
import com.icss.ah.base.action.BaseAction;
import com.icss.ah.base.bean.EasyuiDataGridJson;
import com.icss.ah.login.bean.UserInfoBean;

/**
 * 促销活动统计
 * @author js
 *
 */
@Controller
@Scope("prototype")
public class PromotionStatisticsAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	
	@Autowired
	private PromotionStatisticsService promotionStatisticsService;
	
	private String promotion_Id;//促销编码
	private String shop_Id;//店铺Id
	private String order_Id;//订单号
	private String user_name;//账号
	
	/**
	 * 进入促销活动统计页面
	 * @return
	 */
	public String toPromotionListPage(){
		String returnPage = "toPromotionListPage";
		return returnPage;
	}
	
	/**
	 * 加载列表
	 */
	public void promotionList(){
		request = this.getRequest();
		UserInfoBean userInfoBean= this.getUserInfo(getUserCodeFromSession());
		String shopId = userInfoBean.getShopId();
		String corpId = userInfoBean.getCorpId(); //从配置文件里取公众号id
		String name  = request.getParameter("name")==null?"0":request.getParameter("name").trim();
		String date  = request.getParameter("date")==null?"0":request.getParameter("date").trim();
		String result = "";
		try {
			dataGridJson = new EasyuiDataGridJson();
			HashMap map = new HashMap();
			map.put("corpId",corpId);	//公众号id
			map.put("shopId", shopId);	//商铺id
			map.put("date", date);
			map.put("name", name);
			map.put("startNo",Integer.valueOf(getStartIndexMysql()));
			map.put("pageRows",Integer.valueOf(getEndIndexMysql()));
			List<Map> productList = new ArrayList();
			productList = promotionStatisticsService.getPromotionList("PromotionStatisticBean.getPromotionList", map);
			long productCount = promotionStatisticsService.getPromotionListCount("PromotionStatisticBean.getPromotionListCount", map);//查询总记录数
			dataGridJson.setRows(productList);
			dataGridJson.setTotal(productCount);
			result = JSONObject.fromObject(dataGridJson).toString();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			str2Resp(result);
		}
	}
	
	/**
	 * 跳转明细页面
	 * @return
	 */
	public String detailPage(){
		request = getRequest();
		String returnPage = "toDetailPage";
		request.setAttribute("promotion_Id", promotion_Id);
		return returnPage;
	}

	/**
	 * 促销明细数据
	 * @return
	 */
	public void queryDeatailList(){
		UserInfoBean userInfoBean= this.getUserInfo(getUserCodeFromSession());
		String shopId = userInfoBean.getShopId();
		String corpId = userInfoBean.getCorpId(); //从配置文件里取公众号id
		String result = "";
		try {
			dataGridJson = new EasyuiDataGridJson();
			HashMap map = new HashMap();
			map.put("corpId",corpId);	//公众号id
			map.put("shopId", shopId);	//商铺id
			map.put("order_Id", order_Id);
			map.put("user_name", user_name);
			map.put("promotion_Id", promotion_Id);
			map.put("startIndex", getStartIndexMysql());
			map.put("endIndex", getEndIndexMysql());
			List<Map> productList = new ArrayList();
			productList = promotionStatisticsService.getDetailList("PromotionStatisticBean.getDetailList", map);
			long productCount = promotionStatisticsService.getDetailListCount("PromotionStatisticBean.getDetailListCount", map);//查询总记录数
			dataGridJson.setRows(productList);
			dataGridJson.setTotal(productCount);
			result = JSONObject.fromObject(dataGridJson).toString();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			str2Resp(result);
		}
	}
	
	public String getPromotion_Id() {
		return promotion_Id;
	}

	public void setPromotion_Id(String promotion_Id) {
		this.promotion_Id = promotion_Id;
	}

	public String getShop_Id() {
		return shop_Id;
	}

	public void setShop_Id(String shop_Id) {
		this.shop_Id = shop_Id;
	}

	public String getOrder_Id() {
		return order_Id;
	}

	public void setOrder_Id(String order_Id) {
		this.order_Id = order_Id;
	}

	public String getUser_name() {
		return user_name;
	}

	public void setUser_name(String user_name) {
		this.user_name = user_name;
	}
	
	
}
